#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#include "din.h"

struct dindev*
        dindev_construct(
                void)
{
	int gpionum[6] = {22, 23, 26, 27, 46, 47};
	struct dindev *dev;
	int i;
		
	dev = calloc(1, sizeof(struct dindev));
	if (NULL == dev) {
		perror("calloc dindev");
		return NULL;
	}

	for (i = 0; i < 6; i++) { 
		dev->gpiodev[i] = gpiodev_construct(gpionum[i]);
		if (NULL == dev->gpiodev[i]) {
			printf("gpiodev_construct %d error\n", i);
			return NULL;
		}
		gpiodev_export(dev->gpiodev[i]);
		gpiodev_setdir(dev->gpiodev[i], 1);
	}
	return dev;
}


void
        dindev_deconstruct(
        	struct dindev *dev)
{
	int i;

	for (i = 0; i < 6; i++)
		gpiodev_deconstruct(dev->gpiodev[i]);
	free(dev);
}


int
        dindev_getval(
                struct dindev *dev, int num)
{

	return gpiodev_getval(dev->gpiodev[num]);
}











